/*———————————————————————————————————————封装函数ajax请求并且渲染数据表格—————————————————————————————————————————————*/
	var totalAmount;
	var totalPage;
	var nowPage;
function getAjax(){
	var fareClCde=$("#fareClCde").val();//运价编号
	if(/\((.)+?\)/.test($("#orgCty").val())){//获取出发机场三字码
		var orgCty = $("#orgCty").val().slice(-5).split("(")[1].split(")")[0];
	}else{
		var orgCty = $("#orgCty").val()
	}
	if(/\((.)+?\)/.test($("#dstCty").val())){//获取到达机场三字码
		var dstCty = $("#dstCty").val().slice(-5).split("(")[1].split(")")[0];
	}else{
		var dstCty = $("#dstCty").val()
	}
	
	var owRtCde=$("#owRtCde").val();//运价类型

	var departureDate=$("#departureDate").val();//出发日期
	var flightNums=$("#flightNums").val();//航班编号
	var pageNum = $(".page").val();
	var pageSize = $(".pageSize").val();
	$.ajax({
		type:"get",
		url:"../farebase/farebaseList?fareClCde="+fareClCde+"&orgCty="+orgCty+"&dstCty="+dstCty+"&owRtCde="+owRtCde+"&departureDate="+departureDate+"&flightNums="+flightNums+"&pageNum="+pageNum+"&pageSize="+pageSize+"&temp="+Math.random(),
		dataType:"json",
		success:function(data){
			//每次经行请求时清空页面原有数据
			$(".clear").empty();
			totalAmount = data.data.total;
			if(totalAmount=="0"){
				layer.msg("没有搜索到结果")
				return false;
			}
			totalPage = data.data.pages;
			nowPage = data.data.pageNum;
			//共多少条
			$(".totalAmount").text(totalAmount)
			//共多少页
			$(".totalPage").text(totalPage)
			//第几页
			$(".nowPage").text(nowPage)
				
				var str="";
				var owRtCdeStatus="";//行程类型字符串
				var cbnCdeStatus="";//舱位类型字符串
				var len=data.data.list.length;
				for(var i=0;i<len;i++){
					if(data.data.list[i].owRtCde=="OW"){
						owRtCdeStatus="单程";
					}
					if(data.data.list[i].owRtCde=="RT"){
						owRtCdeStatus="往返";
					}
					
					var flightNums=data.data.list[i].flightNums;
				
					str+='<tr style="text-align:center;">'+
							'<td class="fareClCde_link">'+data.data.list[i].fareClCde+'</td>'+
							'<td style="display:none">'+data.data.list[i].id+'</td>'+
							'<td class="blue_size">'+data.data.list[i].depAirportName+"("+data.data.list[i].orgCty+")"+'</td>'+
							'<td class="blue_size">'+data.data.list[i].arrAirportName+"("+data.data.list[i].dstCty+")"+'</td>'+
							'<td>'+data.data.list[i].effDte+'</td>'+
							'<td>'+data.data.list[i].disDte+'</td>'+
							'<td>'+owRtCdeStatus+'</td>'+
							'<td>'+commomFun.toEmptyString(data.data.list[i].daysOfWeek)+'</td>'+
							'<td>'+data.data.list[i].cbnCde+'</td>'+
							'<td style="display:none">'+data.data.list[i].id+'</td>'+
							'<td><b title="详情" class="detail icon iconfont">&#xe807;</b></td>'+
						'</tr>'+
						'<tr><td  colspan="10" class="hideStatus" style="text-align:left;vertical-align:top;"><span style="display:inline-block;width:44px;"></span>币种：'+commomFun.currencyStr(data.data.list[i].currency)+'<label style=margin-right:60px;></label>价格：<label style=margin-left:20px;>成人价<b class="font_color">￥'+data.data.list[i].adultFare+'</b></label><label style=margin-left:20px;>儿童价格<b class="font_color">￥'+data.data.list[i].childFare+'</b></label><label style=margin-left:20px;>婴儿价格<b class="font_color">￥'+data.data.list[i].infantFare+'</b></label></td></tr>'+
						'<tr><td  colspan="10" class="hideStatus" style="text-align:left;vertical-align:top;"><span style="display:inline-block;width:44px;"></span>适用航班号：'+flightNums.replace(/\//g,"、")+'</td></tr>';
				}
				$(".clear").append(str);
			}
		})

}

//getAjax();

/*__________________________________________查询操作_______________________________________________________*/
$("#searchButton").click(function(){
	$(".page").val("1")
	getAjax();
	
})



/*———————————————————————————————————————详情展开和收起控制—————————————————————————————————————————————*/
$('.tableDate').delegate(".detail","click",function(){
   if($(this).parent().parent().next().children("td").hasClass("hideStatus")){
	   $(this).html("&#xe806;")
	   $(this).parent().parent().next().children("td").removeClass("hideStatus");
	   $(this).parent().parent().next().next().children("td").removeClass("hideStatus");
	   $(this).parent().parent().css("border-bottom","none");
	   $(this).parent().parent().next().css("border-bottom","none");
   }else{
	   $(this).html("&#xe807;")
	   $(this).parent().parent().next().children("td").addClass("hideStatus");
	   $(this).parent().parent().next().next().children("td").addClass("hideStatus");
	   $(this).parent().parent().css("border-bottom","5px solid #f1f1f1");
   }
});




/*———————————————————————————————————————点击运价编号链接设置基础运价页面（此处可查看详情或者编辑）—————————————————————————————————————————————*/
$('.tableDate').delegate(".fareClCde_link","click",function(){
	var id=$(this).next().text();//获取当前行的id值
	layer.open({
		type: 2,
		title: ['管理基础运价信息','background-color:#6d6e72; color:#fff;font-size:14px;'],
		shadeClose: true,
		shade: [0.9,'#cfcfcf'],
		area: ['600px', '75%'],  
		content: ['../ak/setBasicPrice.html?id='+id],// iframe的url，no代表不显示滚动条
		end:function(){
			getAjax();
		}
			
	});
})
/*———————————————————————————————————————新建运价—————————————————————————————————————————————*/
$('.newPrice').click(function(){
	//alert("1")
	layer.open({
		type: 2,
		title: ['新建基础运价信息','background-color:#6d6e72; color:#fff;font-size:14px;'],
		shadeClose: true,
		shade: [0.9,'#cfcfcf'],
		area: ['500px', '75%'],  
		content: ['../ak/newBasicPrice.html'],// iframe的url，no代表不显示滚动条
		end:function(){
			getAjax();
		}
			
	});
})
//____________________________________________出发到达机场条件互换________________
			$(".exchangeAirportCode").click(function(){
				var exchangeVar = $(".queryDep").val();
				$(".queryDep").val($(".queryArr").val());
				$(".queryArr").val(exchangeVar);
			})

			
//________________________________________表头固定____________________________________________
		$("#dataTable").freezeHeader();	
//____________________________________________________________________________机场联想
	airportAutoComplete()	
	function airportAutoComplete(){
			var autocompleteData=[];
			$.ajax({
				type:"get",
				url:"../Airapt?pageSize=100000&pageNum=1&temp="+Math.random(),
				dataType:"json",
				success:function(data){	
					autocompleteData = data.data.list; 
					$('.autocomplete').autocomplete({
					    lookup: autocompleteData,
					    autoSelectFirst:true,
					    onSelect: function (suggestion) {		   
					    }
					});
				}
			})
		}
//________________________________________分页__________________________________
	$(".Pagination").load("Pagination.html",function(){
		getAjax();
	})			

			